package main

import (
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
)

type File struct {
	OldName string
	NewName string
}

func main() {
	dir, _ := os.Getwd()
	fmt.Println(dir, "根目录")
	dirName := filepath.Base(dir)
	fmt.Println(dirName, "文件所在目录")
	fs, _ := os.ReadDir(dir)
	files := make([]File, 0)
	i := 0
	for _, f := range fs {
		if f.IsDir() ||
			strings.Contains(f.Name(), "zrname-tool") ||
			strings.Contains(f.Name(), "main") {
			continue
		}
		e := ""
		if i+1 < 10 {
			e = fmt.Sprintf("0%d", i+1)
		} else {
			e = fmt.Sprintf("%d", i+1)
		}
		if !strings.Contains(f.Name(), e) {
			fmt.Println(f.Name() + ":name no " + e + ",please checked!!")
			break
		}
		i++
		ext := path.Ext(f.Name())
		if ext == "" {
			ext = ".mp4"
		}
		newName := fmt.Sprintf("%sE%s%s", dirName, e, ext)
		fmt.Println(f.Name(), newName)
		files = append(files, File{OldName: f.Name(), NewName: newName})
	}
	for _, fn := range files {
		oldName := dir + "/" + fn.OldName
		newName := dir + "/" + fn.NewName
		if err := os.Rename(oldName, newName); err != nil {
			fmt.Println(err.Error())
		}
	}
	fmt.Println("ok")
}
